package leetcode_acm.array;

import org.junit.Test;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月17日 15:58
 */
public class RemoveDuplicates2 {
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        int slow = 0,fast = 1,count = 1,n = nums.length;
        while (fast < n){
            if(nums[fast] == nums[slow]){
                count++;
                if(count > 2){
                    fast++;
                }else{
                    nums[++slow] = nums[fast++];
                }
                continue;
            }
            nums[++slow] = nums[fast++];
            count = 1;
        }
        return slow+1;
    }
    @Test
    public void test(){
        System.out.println(removeDuplicates(new int[]{1,1,1,2,2,3}));
        System.out.println(removeDuplicates(new int[]{0, 0, 1, 1, 1, 1, 2, 3, 3}));
    }
}
